<?php
/*
Copyright 2008, Nathalia


Author:
Nathalia Sautchuk Patrício          (nathalia.sautchuk@gmail.com)

*/
class Listar extends TPage
{
	public function onInit($param)
    {
        parent::onInit($param);
        
        if($this->Request['all'] == 1)
            $this->Titulo->Text = 'Todas as Avalia&ccedil;&otilde;es';
        else
            $this->Titulo->Text = 'Minhas Avalia&ccedil;&otilde;es';
        
        if($this->Request['status'] == 1)
            $this->Titulo->Text = $this->Titulo->Text.' Finalizadas';
        else
            $this->Titulo->Text = $this->Titulo->Text.' Pendentes';

        if(!$this->IsPostBack)  // if the page is requested the first time
        {
            // populates post data into the repeater
            $this->populateData();
        }
    }
 
    protected function populateData()
    {
        $this->Repeater->DataSource = $this->getAvaliacao();
        $this->Repeater->dataBind();
    }

    protected function getAvaliacao()
    {              
        // Construts a query criteria
        $criteria                          = new TActiveRecordCriteria;
        $criteria->OrdersBy['AvaliacaoID'] = 'asc';
        
        if($this->Request['all'] == 1)
            $criteria->Condition = 'Status = '.$this->Request['status'];
        else
            $criteria->Condition = 'AvaliadorID = '.$this->User->Name.' and Status = '.$this->Request['status'];

        // query for the posts with the above criteria and with author information
        return AvaliacaoRecord::finder()->findAll($criteria);
    }

}
?>
